/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package feesmodule.services;

import feesmodule.domain.Area;
import feesmodule.domain.Jurisdiction;
import feesmodule.domain.JurisdictionServices;
import java.util.Collection;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Oleg
 */
public class DataService implements IDataService
{
    private EntityManagerFactory factory = Persistence.createEntityManagerFactory("FeeRepositoryUT");
    private EntityManager manager;

    public DataService()
    {
        manager = factory.createEntityManager();
    }
    
    public Collection <Area> getAreaDefinitions()
    {
        return (Collection<Area>) manager.createQuery("select a from Area a").getResultList();
    }

    public Jurisdiction getJurisdiction(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

   public void persist(Object o)
    {
      EntityTransaction t =  manager.getTransaction();
      t.begin();
       manager.persist(o);
       t.commit();
    }
   
   public List<JurisdictionServices> getServicesForJurisdiction(int jurisdictionId)
   {
      List<JurisdictionServices> result = (List<JurisdictionServices>) manager.createQuery("select js from JurisdictionServices js where js.jurisdiction.id=" + jurisdictionId).getResultList();
      return result;
   }




}
